<?php
class CMatchcomments extends Zend_Db_Table
{
	protected $_name;
	protected $_primary;

	public function __construct()
	{
		$this->_name = R_PRE."matchcomments";
		$this->_primary = "matchcomments_id";
		parent::__construct();
	}
	
	public function add($row)
	{
		return $this->insert($row);
	}
	
	public function fetchComment($page, $pageNum, $matchId)
	{
		$where = array('MatchID = ?'=>$matchId);
		$order = 'matchcomments_id desc';
		
		$offset = ($page -1) * $pageNum;
		return $this->fetchAll($where, $order, $pageNum, $offset);
	}
	
	public function fetchAllComment($matchId)
	{
		$where = array('MatchID = ?'=>$matchId);
		$order = 'matchcomments_id desc';
		
		return $this->fetchAll($where, $order);
	}
	
	public function getPageCount($pageNum, $matchId)
	{
		$where = array('MatchID = ?'=>$matchId);
		$result = $this->fetchAll($where);
		return ceil(count($result)/$pageNum);
	}
}